/**
 * 
 */
package any.desktop.server.support;

import org.apache.commons.lang.StringUtils;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
import org.springframework.beans.factory.config.AbstractFactoryBean;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
public class DirectoryFactoryBean extends AbstractFactoryBean {
    private String path;

    @Override
    public Class<?> getObjectType() {
        return Directory.class;
    }

    public void setPath(final String path) {
        this.path = path;
    }

    @Override
    protected Object createInstance() throws Exception {
        if (StringUtils.isEmpty(path)) {
            return new RAMDirectory();
        } else {
            return FSDirectory.getDirectory(path);
        }
    }

}
